class TFPawn extends xPawn;

var bool bfound;
var bool bprotected;
var int outpdist;

simulated function PostBeginPlay()
{
    super.PostBeginPlay();

    outpdist=float(tfgame(level.Game).outpostdist)*(float(tfgame(level.Game).outpostarea)/100);
    SetTimer( 1.0, true );
}

simulated function Timer()
{
	local tfoutpost op;
	local tfbasecore bc;

    bfound = false;
    foreach CollidingActors(class'tfoutpost',op,outpdist*48,location)
    {
        if(op.myteam==PlayerReplicationInfo.Team.TeamIndex && op.Health>0 && op.grade>0)
        {
            bprotected = true;
            bfound = true;
        }
    }
    foreach CollidingActors(class'tfbasecore',bc,outpdist*48,location)
    {
        if(bc.myteam==PlayerReplicationInfo.Team.TeamIndex && bc.Health>0)
        {
            bprotected = true;
            bfound = true;
        }
    }
    if(bfound == false)
        bprotected = false;
}

singular event BaseChange()
{
  local float decorMass;

  if ( bInterpolating )
    return;
  if ( (base == None) && (Physics == PHYS_None) )
    SetPhysics(PHYS_Falling);
  // Pawns can only set base to non-pawns, or pawns which specifically allow it.
  // Otherwise we do some damage and jump off.
  else if ( Pawn(Base) != None )
  {
    if ( !Pawn(Base).bCanBeBaseForPawns)
    {
      Base.TakeDamage( (1-Velocity.Z/400)* Mass/Base.Mass, Self,Location,0.5 * Velocity , class'Crushed');
      JumpOffPawn();
    }
  }
  else if ( (Decoration(Base) != None) && (Velocity.Z < -400) )
  {
    decorMass = FMax(Decoration(Base).Mass, 1);
    Base.TakeDamage((-2* Mass/decorMass * Velocity.Z/400), Self, Location, 0.5 * Velocity, class'Crushed');
  }
  else if((tfstation(base)!=none && tfbasecore(base)==none) || tfblockshield(base)!=none) JumpOffPawn();
}

/*simulated function TickFX(float DeltaTime)
{
	local xPlayerReplicationInfo xPRI;
	local int i,NumSkins;

    if ( SimHitFxTicker != HitFxTicker )
    {
        ProcessHitFX();
    }

    // do translocate-out effect
    if( TransEffectTicker != SimTransEffectTicker && Level.NetMode != NM_DedicatedServer )
    {
        SimTransEffectTicker = TransEffectTicker;
        if ( (PlayerReplicationInfo == None) || (PlayerReplicationInfo.Team == None) || (PlayerReplicationInfo.Team.TeamIndex == 0) )
			Spawn(TransOutEffect[0],self,,TransEffectOrigin,rot(16384,0,0));
		else
			Spawn(TransOutEffect[1],self,,TransEffectOrigin,rot(16384,0,0));
    }

	if(FindInventoryType(class'TaskForces.TFShroud')!=none) // Going invisible
	{
        NumSkins = Clamp(Skins.Length,2,4);

        for ( i=0; i<NumSkins; i++ )
		{
			Skins[i] = InvisMaterial;
		}

        // Remove/disallow projectors on invisible people
		Projectors.Remove(0, Projectors.Length);
		bAcceptsProjectors = false;

		// Invisible - no shadow
		if(PlayerShadow != None)
			PlayerShadow.bShadowActive = false;

		// No giveaway flames either
		RemoveFlamingEffects();
	}

	xPRI = xPlayerReplicationInfo(PlayerReplicationInfo);

    if( (PlayerReplicationInfo == None) || (PlayerReplicationInfo.Team == None) || (Level.NetMode == NM_DedicatedServer)
		|| class'DeathMatch'.Default.bNoCoronas || class'DMMutator'.Default.bBrightSkins || bPlayedDeath
		|| (xPRI != None && xPRI.bForceNoPlayerLights) )
        return;

	if ( LeftMarker == None && !bInvis )
	{
		LeftMarker = Spawn(class'PlayerLight',self,,Location);
		if( !AttachToBone(LeftMarker,'lshoulder') )
		{
			log( "Couldn't attach LeftMarker to lshoulder", 'Error' );
			LeftMarker.Destroy();
			return;
		}

		RightMarker = Spawn(class'PlayerLight',self,,Location);
		if( !AttachToBone(RightMarker,'rshoulder') )
		{
			log( "Couldn't attach RightMarker to rshoulder", 'Error' );
			RightMarker.Destroy();
			return;
		}

		LeftMarker.SetRelativeLocation(LeftOffset);
		RightMarker.SetRelativeLocation(RightOffset);
		if ( PlayerReplicationInfo.Team.TeamIndex == 0 )
		{
			RightMarker.Texture = Texture'RedMarker_t';
			LeftMarker.Texture = Texture'RedMarker_t';
		}
		else
		{
			RightMarker.Texture = Texture'BlueMarker_t';
			LeftMarker.Texture = Texture'BlueMarker_t';
		}
	}
	else if( LeftMarker != None && bInvis )
	{
		LeftMarker.Destroy();
		RightMarker.Destroy();
	}
}*/

function int ShieldAbsorb( int damage )
{
    local int damagethru;

    if (ShieldStrength == 0)
    {
        return damage;
    }

    damagethru=damage/4; //the shield in TF absorbs only 75%
    damage-=damagethru;

    if (ShieldStrength > damage)
    {
        ShieldStrength -= damage;
		SetOverlayMaterial( ShieldHitMat, ShieldHitMatTime, false );
	    PlaySound(sound'WeaponSounds.ArmorHit', SLOT_Pain,TransientSoundVolume*(float(damage)/10),,400);
        return damagethru;
    }
    else
    {
		damage -= ShieldStrength;
        SetOverlayMaterial( ShieldHitMat, ShieldHitMatTime, false );
        ShieldStrength = 0;
        return damagethru+damage;
    }
}

function SetInvisibility(float time)
{
    bInvis = (time > 0.0);
    if (Role == ROLE_Authority)
    {
        if (bInvis)
		{
			Visibility = 0;
			MaxLights=0;
			bUseDynamicLights=false;
			bAcceptsProjectors=false;
			if(weapon!=none)
			{
                weapon.MaxLights=0;
			    weapon.bUseDynamicLights=false;
			    weapon.bAcceptsProjectors=false;
            }
            SetWeaponOverlay(InvisMaterial, time, true);
        }
        else
        {
			MaxLights=8;
            bUseDynamicLights=true;
			bAcceptsProjectors=true;
			if(weapon!=none)
			{
			weapon.MaxLights=weapon.default.MaxLights;
            weapon.bUseDynamicLights=true;
			weapon.bAcceptsProjectors=true;
            }
            Visibility = Default.Visibility;
            SetWeaponOverlay(None, 0.0, true);
        }
    }
}

function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, class<DamageType> damageType)
{
    if(bprotected) Damage/=1.25;

    super.TakeDamage(Damage, instigatedBy, hitlocation, momentum, damageType);
}

defaultproperties
{
     InvisMaterial=FinalBlend'TFMedia.Equipment.TFShroud'
     ShieldStrengthMax=199.000000
     bprotected=false
}
